#include "Item_by_rev.h"
#include <algorithm>
using namespace std;

Item_by_rev::Item_by_rev(){}

void Item_by_rev::Show_Top_Five(vector<Order_Item> order_items, vector<Menu_Item> menu_items)
{
	double most_sold, second, third, fourth, fifth;	//variables for storing the id_numbers of the top five sold items
	 
	int num_items;
	double item_revenue;

	vector<double> revenues; 
	vector<double> sorted_revenues;

	for(unsigned int i = 0; i < menu_items.size(); i++) //searches through menu_items vector
		{
		item_revenue = 0; //resets the current item's revenue accumulator
			for(unsigned int j = 0; j < order_items.size(); j++)//searches through order_items vector
			{
				if(menu_items[i].item_id()==order_items[j].menu_item()) //compares menu_items to order_items
				{
				item_revenue += menu_items[i].item_price(); //increases the revenue for the current item by the item price 
															//when the item id's are identical
				}
			}
		sorted_revenues.push_back(item_revenue); //the item id and revenue is stored in a vector in same order as menu_items
		}

		sort(sorted_revenues.begin(), sorted_revenues.end()); // the vector full of items and revenues is sorted from least to greatest price
		num_items = sorted_revenues.size() - 1;
		
		most_sold = sorted_revenues[num_items];
		second = sorted_revenues[num_items-1];
		third = sorted_revenues[num_items-2];
		fourth = sorted_revenues[num_items-3];
		fifth = sorted_revenues[num_items-4];
		
		cout << "The top five revenues are: " << endl;
		cout << most_sold << "\n" << second << '\n' << third << "\n" << fourth << "\n" << fifth << "\n";
	}
 //  


		
		
